package com.example.moshudriver.protocol;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.external.activeandroid.DataBaseModel;
import com.external.activeandroid.annotation.Column;
import com.external.activeandroid.annotation.Table;

@Table(name = "usersignupRequest")
public class usersignupRequest  extends DataBaseModel
{

     @Column(name = "platform")
     public String   platform;

     @Column(name = "mobile_phone")
     public String   mobile_phone;

     @Column(name = "location")
     public LOCATION   location;

     @Column(name = "nickname")
     public String   nickname;

     @Column(name = "invite_code")
     public String   invite_code;

     @Column(name = "ver")
     public int ver;

     @Column(name = "password")
     public String   password;
     
     @Column(name = "avatar")
     public String   avatar;
     
     @Column(name = "identity_card")
     public String   identity_card;


     @Column(name = "gender")
     public int gender;
     
     @Column(name = "moto_id")
     public String moto_id;


     public void  fromJson(JSONObject jsonObject)  throws JSONException
     {
          if(null == jsonObject){
            return ;
           }

          JSONArray subItemArray;

          this.platform = jsonObject.optString("platform");
          
          this.platform = jsonObject.optString("moto_id");

          this.mobile_phone = jsonObject.optString("mobile_phone");
          LOCATION  location = new LOCATION();
          location.fromJson(jsonObject.optJSONObject("location"));
          this.location = location;

          this.nickname = jsonObject.optString("nickname");

          this.invite_code = jsonObject.optString("invite_code");

          this.ver = jsonObject.optInt("ver");
          
          this.avatar = jsonObject.optString("avatar");
          
          this.gender = jsonObject.optInt("gender");
          
          this.identity_card = jsonObject.optString("identity_card");

          this.password = jsonObject.optString("password");
          return ;
     }

     public JSONObject  toJson() throws JSONException 
     {
          JSONObject localItemObject = new JSONObject();
          JSONArray itemJSONArray = new JSONArray();
          localItemObject.put("platform", platform);
          localItemObject.put("mobile_phone", mobile_phone);
          if(null != location)
          {
            localItemObject.put("location", location.toJson());
          }
          localItemObject.put("nickname", nickname);
          localItemObject.put("invite_code", invite_code);
          localItemObject.put("ver", ver);
          localItemObject.put("avatar", avatar);
          localItemObject.put("moto_id", moto_id);
          localItemObject.put("gender", gender);
          localItemObject.put("identity_card", identity_card);
          localItemObject.put("password", password);
          return localItemObject;
     }

}
